from datetime import datetime

DB_ID = {}


def createId(key):
    _vaule = 1
    try:
        if DB_ID[key] >= 9999:
            _vaule = 1
        else:
            _vaule = DB_ID[key] + 1
    except KeyError:
        pass
    DB_ID[key] = _vaule

    _str = "%s%s%s" % (key.upper(), datetime.now().strftime('%Y%m%d%H%M%S%f'), toStr(_vaule))
    return _str


def toStr(value):
    if len(str(value)) == 1:
        return '000%s' % value
    elif len(str(value)) == 2:
        return '00%s' % value
    elif len(str(value)) == 3:
        return '00%s' % value
    else:
        return value


if __name__ == '__main__':
    print createId('a')
